Pokerface.addComponent(new Pokerface.Component.extend({
    _pauseUpdates: false,
    _id: 0,

    // protected methods
    _update: function(self) {
        if (this._pauseUpdates) {
            return;
        }
        // @TODO long pooling here
        setTimeout(function(){
            $.ajax({
                url: '/game/update',
                type: 'POST',
                dataType: 'json',
                data: 'id=' + self._id,
                success: function(data) {
                    console.log(data);
                },
                complete: function() {
                    self._update(self);
                }
            });
        }, 3000);
    },

    // public
    getName: function(){
       return 'table';
    },

    start: function() {
        var self = this;
        this._id = Pokerface._currentTableId;
        this._pauseUpdates = false;
        this._update(this);

        $('#quit').show().unbind('click').click(function(){
            self._pauseUpdates = true;
            $.ajax({
                url: '/game/stand',
                type: 'POST',
                dataType: 'json',
                data: 'id=' + self._id,
                success: function(data){
                    self._pauseUpdates = true;
                    $('#quit').hide();
                    $('#table').fadeOut(200, function(){
                        $('#games_list').fadeIn(200);
                    });
                    Pokerface.start('tableList');
                }
            });
            return false;
        });
    }
})());